//
//  CRSessionConfigurator.m
//  TestPrj
//
//  Created by 朱铅峰 on 2020/10/21.
//  Copyright © 2020 Xing. All rights reserved.
//

#import "CRSessionConfigurator.h"
#import "CRSessionInteractorImpl.h"
#import "CRSessionDataSourceImpl.h"
#import "CRSessionTableAdapter.h"


/*
                                            CRSessionViewController 类关系图
 
 
             .........................................................................
             .                                                                       .
             .                                                                       .
             .                                                                       .                  | ---> [CRSessionDatasource]
             .                                                                       .
             .                                                       | ---> [CRSessionInteractor] -->  |
             .
             .                                                                                          | ---> [CRSessionLayout]
             .
             ↓
  [CRSessionViewController]-------> [CRSessionConfigurator] -----> |
             |
             |
             |
             |
             ↓                                                       | ---> [CRSessionTableAdapter]
       [UITableView]                                                              .
            ↑                                                                     .
            .                                                                     .
            .                                                                     .
            .......................................................................
 */
@interface CRSessionConfigurator()

@property (nonatomic,strong) CRSessionInteractorImpl   *interactor;

@property (nonatomic,strong) CRSessionTableAdapter     *tableAdapter;

@end

@implementation CRSessionConfigurator

- (void)setup:(ChatRoomHomeViewController *)vc {
    
    CRSession *session    = vc.session;
    UITableView *tableView  = vc.tableView;
    CRInputView *inputView = vc.sessionInputView;
    
    CRSessionDataSourceImpl *datasource = [[CRSessionDataSourceImpl alloc] initWithSession:session config:nil];
    CRSessionLayoutImpl *layout         = [[CRSessionLayoutImpl alloc] initWithSession:session config:nil];
    layout.tableView = tableView;
    layout.inputView = inputView;
    
    
    _interactor                          = [[CRSessionInteractorImpl alloc] initWithSession:session config:nil];
    _interactor.delegate                 = vc;
    _interactor.dataSource               = datasource;
    _interactor.layout                   = layout;
    
    [layout setDelegate:_interactor];
    
    _tableAdapter = [[CRSessionTableAdapter alloc] init];
    _tableAdapter.interactor = _interactor;
    _tableAdapter.delegate   = vc;
    vc.tableView.delegate = _tableAdapter;
    vc.tableView.dataSource = _tableAdapter;
    
    [vc setInteractor:_interactor];
}


@end
